﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace AjaxToolkitDemo
{
    public partial class DropDownExt : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Image1.ImageUrl = "Images/001.jpg";

            var customers = Customer.GetSampleData();
            GridView1.DataSource = customers;
            GridView1.DataBind();
            GridView1.SelectedIndexChanged += new EventHandler(GridView1_SelectedIndexChanged);
            GridView1.RowCommand += new GridViewCommandEventHandler(GridView1_RowCommand);
            GridView1.PageIndexChanging += new GridViewPageEventHandler(GridView1_PageIndexChanging);
        }

        void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            var customers = Customer.GetSampleData( e.NewPageIndex);
            GridView1.DataSource = customers;
            GridView1.DataBind();            
        }
 
        void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
           string cmd=  e.CommandName;
            //TextBox2.Text = GridView1.Rows[GridView1.SelectedIndex].Cells[0].Text ;
            
        }

       protected   void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            TextBox2.Text = (string)GridView1.SelectedValue;
        //    TextBox2.Text = GridView1.SelectedRow.Cells[0].Text;
        }

        protected void option_Click(object sender, EventArgs e)
        {
            //Image1.ImageUrl = string.Format("images/{0}.jpg",  ((LinkButton)sender) .Text);
           Image1.ImageUrl =  ((Image) (((LinkButton)sender).Controls[0])).ImageUrl;
          //  var k = ((LinkButton)sender);
        }

        protected void image_Click(object sender, EventArgs e)
        {
            Image1.ImageUrl =  ((Image)sender).ImageUrl  ;
        }
    }

    public class Customer
    {
        public string ID { get; set; }
        public string Name { get; set; }
        public DateTime CreateDate { get; set; }

        public static  List<Customer> GetSampleData()
        {
            Random rand = new Random();
           int count=  rand.Next(5,15);
            List<Customer> customers = new List<Customer>();
            for (int i = 0; i < count ; i++)
                customers.Add(new Customer { ID = "Cust" + i, Name = "Customer 00" + i, CreateDate = DateTime.Now.AddDays(i) });
            return customers;
        }

        public static  List<Customer> GetSampleData(int page)
        {
            Random rand = new Random();
            int count = 5;
            List<Customer> customers = new List<Customer>();
            for (int i = page *count ; i < count*(page +1) ; i++)
                customers.Add(new Customer { ID = "Cust" + i, Name = "Customer 00" + i, CreateDate = DateTime.Now.AddDays(i) });
            return customers;
        }
    }

    public class Employee
    {
        public string ID { get; set; }
        public string Name { get; set; }
        public DateTime CreateDate { get; set; }

        public static List<Employee> GetSampleData()
        {
            Random rand = new Random();
            int count = rand.Next(5, 15);
            List<Employee> customers = new List<Employee>();
            for (int i = 0; i < count; i++)
                customers.Add(new Employee { ID = "Emp" + i, Name = "Employee 00" + i, CreateDate = DateTime.Now.AddDays(i) });
            return customers;
        }
    }

    public class Product
    {
        public string ID { get; set; }
        public string Name { get; set; }
        public DateTime CreateDate { get; set; }

        public static List<Product> GetSampleData()
        {
            Random rand = new Random();
            int count = rand.Next(5, 15);
            List<Product> customers = new List<Product>();
            for (int i = 0; i < count; i++)
                customers.Add(new Product { ID = " Prod" + i, Name = " Product 00" + i, CreateDate = DateTime.Now.AddDays(i) });
            return customers;
        }
    }
}
